package com.asset.web.system;

import com.asset.pojo.Depository;
import com.asset.service.DepositoryService;
import com.asset.util.PageResult;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 仓库管理
 * @author 11725
 */
@RestController
@RequestMapping("/depository")
public class DepoController {

    @Resource
    private DepositoryService depoService;

    /**
     * 分页查询 | 查询全部信息
     * @param page          页码
     * @param rows          行数
     * @param selectAll     是否查询全部
     * @return              结果集
     */
    @GetMapping("/list")
    public ResponseEntity<PageResult> selectByPage(
            @RequestParam(value = "page", defaultValue = "1") Integer page,
            @RequestParam(value = "rows", defaultValue = "10") Integer rows,
            @RequestParam(value = "selectAll", required = false) Boolean selectAll) {
        return ResponseEntity.ok(depoService.selectByPage(page, rows, selectAll));
    }

    /**
     * 新增仓库信息
     * @param depository    Depository 对象
     * @return              void
     */
    @PostMapping
    public ResponseEntity<Void> insert(@RequestBody Depository depository) {
        depoService.insert(depository);
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }

    /**
     * 修改仓库信息
     * @param depository    Depository 对象
     * @return              void
     */
    @PutMapping
    public ResponseEntity<Void> update(@RequestBody Depository depository) {
        depoService.update(depository);
        return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
    }

    /**
     * 删除仓库信息
     * @param id            仓库 id
     * @return              void
     */
    @DeleteMapping("/{id}")
    public ResponseEntity<Void> delete(@PathVariable("id") Long id) {
        return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
    }
}
